/**
 * @projectName study-note
 * @package middle
 * @className middle.BuildTree
 */
package middle;

import node.TreeNode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

/**
 * BuildTree
 * @description 重建二叉树
 * 输入某二叉树的前序遍历和中序遍历的结果，请构建该二叉树并返回其根节点。
 * 假设输入的前序遍历和中序遍历的结果中都不含重复的数字。
 * @author answer_wx
 * @date 2022/7/10 23:13
 * @version 1.0
 */
public class BuildTree {
    public static TreeNode buildTree(int[] preorder, int[] inorder) {
        if (preorder == null || preorder.length == 0) {
            return null;
        }
        TreeNode root = new TreeNode();
        List<Integer> tmp = new ArrayList<>();
        int length = preorder.length;
        for (int i = 0; i < length; i++) {
            if (i == 0) {
                tmp.add(preorder[i]);
                break;
            }
        }
        return root;
    }

    public static int indexOf(int[] arr, int target) {
        if (arr.length == 0) {
            return -1;
        }
        int s = 0, e = arr.length - 1;
        while (s <= e) {
            int mid = s + (e - s) >> 1;
            if (arr[mid] < target) {
                s = mid + 1;
            }
            if (arr[mid] > target) {
                e = mid - 1;
            }
            if (arr[mid] == target) {
                return mid;
            }
        }
        return -1;

    }

    public static void main(String[] args) {
        int[] preorder = {3, 9, 20, 15, 7}, inorder = {9, 3, 15, 20, 7};
//        buildTree(preorder, inorder);
        TreeNode treeNode = new TreeNode(0, new TreeNode(1), new TreeNode(2));
        treeNode.left = new TreeNode(4);
    }
}